Skip to content

chore(benchmarks): run the JMH benchmarks with quiet logging - #1083

Merged
DemchaAV merged 2 commits into
developfrom
chore/benchmarks-jmh-quiet-logging
Nov 23, 2026
Merged

DemchaAV merged 2 commits into
developfrom
chore/benchmarks-jmh-quiet-logging

Conversation

@DemchaAV

@DemchaAV DemchaAV commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Why

The JMH layer measured the engine with its DEBUG logging switched on. Only the manual harness applies logback-benchmark.xml (BenchmarkSupport.configureQuietLogging()); the classes under com.demcha.compose.jmh never called it, and benchmarks.jar carries no logback.xml, so every forked JVM fell back to Logback's default configuration — root at DEBUG, to the console.

Measured on develop (6ec0d7474), -prof gc, the benchmarks' own fork counts:

Run Output DEBUG lines
CanonicalRenderJmhBenchmark -bm avgt (1 fork) 32.8 MB 129 193
DocxExportJmhBenchmark.docx, 4 shapes (1 fork each) 22.2 MB 78 487
ColdStartJmhBenchmark, 3 benchmarks (10 forks each) 25.9 MB 104 000

What changed

  • QuietJmhBenchmark (new, com.demcha.compose.jmh) — abstract base whose static initializer calls BenchmarkSupport.configureQuietLogging() and then initializes Logback (LoggerFactory.getILoggerFactory()), so Logback's start-up is outside every measured region. All 14 JMH benchmarks extend it.
    • Why a superclass rather than @Fork(jvmArgsAppend = "-Dlogback.configurationFile=…"): JMH 1.37 takes a command-line -jvmArgsAppend instead of the annotation's (Runner: options.getJvmArgsAppend().orElse(benchmark.getJvmArgsAppend()…)), so a run passing -Xmx that way would get the logging back without a sign. A superclass is initialized before its subclass (JLS 12.4.2) and before any @Setup, so the hook holds whatever JVM arguments the run appends, short of the opt-outs below, and however a benchmark orders its own static fields.
    • Why not a logback.xml in the module's resources: the manual harness's -Dgraphcompose.benchmark.logging=debug works by leaving Logback with no configuration to find; a logback.xml would silence it.
    • The opt-outs carry over unchanged, passed to the fork with -jvmArgsAppend: -Dgraphcompose.benchmark.logging=debug keeps the engine's logging, and an explicit -Dlogback.configurationFile wins.
  • BenchmarkSupport becomes public (with configureQuietLogging(), now documented) so the jmh package can call it. Its behaviour is unchanged; the manual harness and ab-bench call it as before. The module is not deployed and not in the knowledge pack.
  • JmhQuietLoggingGuardTest (new) — reads META-INF/BenchmarkList, the list the JMH runner reads, plus the @State classes the benchmarks' @Benchmark/@Setup/@TearDown methods take (in any package, followed through the states' own fixture methods) and every @State class compiled into the package, so a benchmark or state class added later is checked without being named. Each class is initialized in a fresh class loader over the test classpath and that loader's SLF4J is asked whether com.demcha.compose logs at DEBUG. Two more cases keep the guard honest: with nothing initialized the classpath is loud (a logback.xml arriving on it would otherwise make every class pass), and the debug opt-out still logs.
  • benchmarks/README.md, docs/operations/benchmarks.md and the CHANGELOG say how the JMH layer logs and how to opt out. JMH results recorded before 2.5.2 — the weekly benchmarks-jmh.yml series among them — are not comparable with later ones.

Verification

The same runs on the jar built from this branch:

Run Output DEBUG lines gc.alloc.rate.norm, before → after
CanonicalRender 6 KB 0 333 172 → 273 169 B/op (−18.0 %)
DocxExport.docx 19 KB 0 small −3.3 %, table1000 −4.8 %, images20 −1.1 %, report20 +0.1 % (error ±7.5 %)
ColdStart 34 KB 0 CV template −12.5 %, engine-simple −13.2 %, invoice template −13.2 % per shot

The allocation column is the steadier one, not a noise-free one: with one fork the per-shape error is ±1–8 %, so only CanonicalRender, ColdStart and table1000 move clearly past it. Average time moved with the logging gone (CanonicalRender 2.4 → 0.5–1.6 ms/op across two runs, ColdStart engine-simple 2373 → 1194–1265 ms), but on a machine that was not kept quiet those error bars are wide. Initializing Logback in the hook changed ColdStart allocation by ≤ 0.1 % against the hook alone.

  • java -jar benchmarks.jar CanonicalRenderJmhBenchmark -jvmArgsAppend "-Dgraphcompose.benchmark.logging=debug" prints DEBUG again (3 452 lines in a 1-iteration run); the same run with -jvmArgsAppend "-Xmx1g" prints none.
  • ./mvnw -B -ntp test -f benchmarks/pom.xml — 47 tests, 0 failures (JmhQuietLoggingGuardTest 3).
  • Each rule broken once, and the named guard case fails on it, 3 tests run each time — 8 of 8, each failure naming the class it planted: a benchmark not extending the base; a @State class of the package not in BenchmarkList not extending it; a @State class in com.demcha.compose taken only by a @Benchmark method not extending it; one taken only by another state's @Setup method; the hook emptied; the hook moved to an instance initializer; a logback.xml on the test classpath; the debug opt-out removed.
  • ./mvnw -B -ntp clean verify of the CI reactor (core, render-pdf/docx/pptx, templates, testing, qa, coverage), the JDK 17 knowledge checks, core javadoc, install and the examples tests on 228ed3028 — all pass (reactor 1926 tests, examples 93, 0 failures). The benchmarks module is outside that reactor; CI's Performance Smoke Check runs its tests.

Lane: build / benchmark tooling. No library code, no public API, no knowledge-pack change.

Only the manual harness applied logback-benchmark.xml. A forked JMH JVM
found no Logback configuration, fell back to Logback's default and printed
every engine DEBUG line to the console: 32.8 MB for one CanonicalRender
fork, 22.2 MB for the four DocxExport.docx shapes, 25.9 MB for ColdStart,
and the logging was inside the measured region.

Every JMH benchmark now extends QuietJmhBenchmark, whose static initializer
calls BenchmarkSupport.configureQuietLogging() and initializes Logback before
the fork loads anything that logs. A superclass is initialized before its
subclass, so the hook holds however a benchmark orders its own static
fields, and it does not depend on the JMH command line: a -jvmArgsAppend
given for another reason replaces a jvmArgsAppend declared in @fork. The
manual harness's opt-out, -Dgraphcompose.benchmark.logging=debug, works the
same through -jvmArgsAppend. A logback.xml in the module's resources would
have been simpler, but the manual harness's opt-out relies on Logback
finding no configuration at all.

JmhQuietLoggingGuardTest reads META-INF/BenchmarkList and every @State class
of the package, initializes each in a class loader of its own and asks that
loader's SLF4J whether the engine logs at DEBUG, so a benchmark added later
is checked without being named.
The guard also follows the @State parameters of the benchmarks' @benchmark, @setup and @teardown methods, so a state class outside the jmh package is checked too. The CHANGELOG claims an allocation drop only where it exceeds the run's error, and ColdStart's javadoc records that Logback starts outside the shot.
@DemchaAV
DemchaAV marked this pull request as ready for review November 23, 2026 14:35
@DemchaAV
DemchaAV merged commit 4e9fb9c into develop Nov 23, 2026
11 checks passed
@DemchaAV
DemchaAV deleted the chore/benchmarks-jmh-quiet-logging branch November 23, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant